$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        init:function () {
            $('.tab-pane').each(function () {
               var height = $(document.body).outerHeight(true) - 39 -47 - 100;
               $(this).height(height);
            });
            this.listener();
        },
        listener:function () {
            var $this = this;
            //转正申请
            $('#btn_regular').click(function () {
                $this.funObj().regular();
            });
            //查看转正
            $('#btn_seeRegular').click(function () {
                $this.funObj().seeRegular();
            });
            //岗位调动
            $('#btn_seeTransfer').click(function () {
                $this.funObj().transfer();
            });
            //离职申请
            $('#btn_quit').click(function () {
                $this.funObj().quitForm();
            });
            //查看离职申请
            $('#btn_seeQuit').click(function () {
               $this.funObj().goToQuit();
            });

            $(window).resize(function () {          //当浏览器大小变化时
                $('.tab-pane').each(function () {
                    var height = $(document.body).outerHeight(true) - 39 -47 - 100;
                    $(this).attr('style','height:'+height+'px;');
                });
            });
        },
        funObj:function () {
            var $this = this;
            return {
                regular:function () {
                    window.top.swal({
                        showCancelButton: true,
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: false,
                        title: '试用转正总结',
                        input: 'textarea',
                        preConfirm: function(explain) {
                            return new Promise(function (resolve, reject) {
                                if(!explain){
                                    reject('说明不能为空！');
                                }
                                else {
                                    resolve(explain);
                                }
                            })
                        }
                    }).then(function (explain) {
                        xhExtra.ajaxRequest('hrm/mine/addRegular',{staffId:staffId,desc:explain},{},function (res) {
                            window.top.xhTop.showSuccess(res.msg);
                            location.reload();
                        })
                    },function (dismiss) {
                        return false;
                    });
                },
                seeRegular:function () {
                    window.top.xhTop.createNewTab('转正审批列表',baseUrl+'hrm/mine/regularList?staffId='+staffId)
                },
                transfer:function () {
                    window.top.xhTop.createNewTab('岗位调动列表',baseUrl+'hrm/mine/transferList?staffId='+staffId)
                },
                quitForm:function () {
                    window.top.swal({
                        showCancelButton: true,
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: false,
                        title: '离职理由',
                        input: 'textarea',
                        preConfirm: function(explain) {
                            return new Promise(function (resolve, reject) {
                                if(!explain){
                                    reject('说明不能为空！');
                                }
                                else {
                                    resolve(explain);
                                }
                            })
                        }
                    }).then(function (explain) {
                        xhExtra.ajaxRequest('hrm/mine/addDismiss',{staffId:staffId,desc:explain},{},function (res) {
                            window.top.xhTop.showSuccess(res.msg);
                            location.reload();
                        })
                    },function (dismiss) {
                        return false;
                    });
                },
                goToQuit:function () {
                    window.top.xhTop.createNewTab('离职申请列表',baseUrl+'hrm/mine/dismissList?staffId='+staffId)
                }
            }
        }
    }
};